home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / hity wydania / Ubuntu 9.10 PL / karmelkowy-koliberek-desktop-9.10-i386-PL.iso / casper / filesystem.squashfs / usr / lib / python2.6 / glob.pyc (.txt) < prev    next >
Python Compiled Bytecode  |  2009-11-11  |  2KB  |  87 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyc (Python 2.6)
  3.  
  4. '''Filename globbing utility.'''
  5. import sys
  6. import os
  7. import re
  8. import fnmatch
  9. __all__ = [
  10.     'glob',
  11.     'iglob']
  12.  
  13. def glob(pathname):
  14.     '''Return a list of paths matching a pathname pattern.
  15.  
  16.     The pattern may contain simple shell-style wildcards a la fnmatch.
  17.  
  18.     '''
  19.     return list(iglob(pathname))
  20.  
  21.  
  22. def iglob(pathname):
  23.     '''Return an iterator which yields the paths matching a pathname pattern.
  24.  
  25.     The pattern may contain simple shell-style wildcards a la fnmatch.
  26.  
  27.     '''
  28.     if not has_magic(pathname):
  29.         if os.path.lexists(pathname):
  30.             yield pathname
  31.         
  32.         return None
  33.     (dirname, basename) = os.path.split(pathname)
  34.     if not dirname:
  35.         for name in glob1(os.curdir, basename):
  36.             yield name
  37.             has_magic(pathname)
  38.         
  39.         return None
  40.     if has_magic(basename):
  41.         glob_in_dir = glob1
  42.     else:
  43.         glob_in_dir = glob0
  44.     for dirname in dirs:
  45.         for name in glob_in_dir(dirname, basename):
  46.             yield os.path.join(dirname, name)
  47.         
  48.     
  49.  
  50.  
  51. def glob1(dirname, pattern):
  52.     if not dirname:
  53.         dirname = os.curdir
  54.     
  55.     if isinstance(pattern, unicode) and not isinstance(dirname, unicode):
  56.         if not sys.getfilesystemencoding():
  57.             pass
  58.         dirname = unicode(dirname, sys.getdefaultencoding())
  59.     
  60.     
  61.     try:
  62.         names = os.listdir(dirname)
  63.     except os.error:
  64.         return []
  65.  
  66.     if pattern[0] != '.':
  67.         names = filter((lambda x: x[0] != '.'), names)
  68.     
  69.     return fnmatch.filter(names, pattern)
  70.  
  71.  
  72. def glob0(dirname, basename):
  73.     if basename == '':
  74.         if os.path.isdir(dirname):
  75.             return [
  76.                 basename]
  77.     elif os.path.lexists(os.path.join(dirname, basename)):
  78.         return [
  79.             basename]
  80.     return []
  81.  
  82. magic_check = re.compile('[*?[]')
  83.  
  84. def has_magic(s):
  85.     return magic_check.search(s) is not None
  86.  
  87.